package cn.okcmd.juc;

import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;

/**
 * create by caoqg on 2021/7/16
 * 功能说明:
 */
@Slf4j
public class TestAtomic {
    public static void main(String[] args) {
        AtomicInteger atomicInteger = new AtomicInteger();
        int numInt = atomicInteger.incrementAndGet();
        log.info("this is int:{}",numInt);

        AtomicLong atomicLong = new AtomicLong(100);
        long numLong = atomicLong.addAndGet(100);
        log.info("this is long:{}",numLong);

        String ref1 = new String("str1");
        String ref2 = new String("str2");
        AtomicReference<String> atomicReference = new AtomicReference<>(ref1);
        boolean setSucc = atomicReference.compareAndSet(ref1, ref2);
        log.info("this is ref,set:{},befor:{},then:{}", setSucc, ref1, ref2);
    }
}
